//
//  StepArchiveModel.swift
//  DaRings
//
//  Created by 尹琼 on 2023/2/23.
//

import UIKit
import SQLite
import HandyJSON
import SwiftDate
import SQLiteValueExtension
import MYModule

open class StepArchiveModel: NSObject, MYSQLiteTableiabe, FullDaySQLite, HandyJSON {
    
    public var adress: String = ""
    
    
    public var id: Int64 = 0
    
    /// 存储数据日期
    public var date: Date = Date().sqlDate()
    
    /// 步数详情(半小时归档一次)
    public var steps: [Int] = []
    
    /// 数据更新日期
    /// 注意： 步数归档更新日期 使用 stepsUpdateTime
    public var updateTime: Double = 0
    
    
    public var isEmpty: Bool {
        
        return steps.filter { $0 > 0 }.isEmpty
        
    }
    
    required public override init() {}
    
    public func updateData() {
        
        guard let _ = StepArchiveModel.day(date: date) else {
            insert()
            return
        }
        
        update()
      
    }

}
